﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace TyNetCoreBlog.Models.Entities
{
    public class Blog
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }



        [Display(Name = "博客标题")]
        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(200, ErrorMessage = "{0}不能超过100字")]
        public string Title { get; set; }


        [Display(Name = "博客简介")]
        [StringLength(200, ErrorMessage = "{0}不能超过100字")]
        public string Description { get; set; }


        [Display(Name = "博客内容")]
        [Required(ErrorMessage = "{0}不能为空")]
        [DataType(DataType.MultilineText)]
        public string Contents { get; set; }


        [Required(ErrorMessage = "{0}不能为空")]
        [Display(Name = "标识")]
        public string Flag { get; set; }


        [Display(Name = "浏览次数")]
        public int Views { get; set; }


        [Display(Name = "是否开启声明")]
        public bool ShareStatement { get; set; }    //转载申明是否开启



        [Display(Name = "是否发布")]
        public bool Published { get; set; }


        [Display(Name = "创建时间")]
        [DataType(DataType.DateTime)]
        public DateTime CreateTime { get; set; }


        [Display(Name = "更新时间")]
        [DataType(DataType.DateTime)]
        public DateTime UpdateTime { get; set; }


        [ForeignKey("UserId")]
        public User User { get; set; }
        public int UserId { get; set; }


        [ForeignKey("CategoryId")]
        public virtual Category Category { get; set; }    //关联分类

        [Display(Name = "分类id")]
        public int CategoryId { get; set; }     //分类id


        public virtual ICollection<BlogTag> BlogTags { get; set; }      //关联中间表
    }
}
